/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormBonus.java
 *
 * Created on Feb 2, 2011, 4:49:20 PM
 */

package juwita;

import config.DBConnection;
import java.awt.CardLayout;
import java.sql.*;
import javax.swing.ButtonGroup;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
import javax.swing.table.TableColumn;


/**
 *
 * @author Abah
 */
public class FormBonus extends javax.swing.JInternalFrame {

    private DefaultTableModel DftTabModeBonusPeg;
    private DefaultTableModel DftTabModePegawai;
    java.sql.Connection conn = new DBConnection().connect();
  
    /** Creates new form FormBonus */
    public FormBonus() {
        initComponents();
        ButtonGroup group = new ButtonGroup();
        group.add(rbBungkus);
        group.add(rbPenjualan);
        
        btnEdit.setEnabled(false);
        btnDelete.setEnabled(false);
        tbBonusPeg.getTableHeader().setReorderingAllowed(false);
        tbPegawai.getTableHeader().setReorderingAllowed(false);
        setKdBonusPeg();

        tampilDataBonusPeg();
       
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnTengah = new javax.swing.JPanel();
        pnAtas = new javax.swing.JPanel();
        btnDelete = new javax.swing.JButton();
        txtUserName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtKdBonus = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtKet = new javax.swing.JTextArea();
        btnNew = new javax.swing.JButton();
        txtNmPegawai = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtBnsBksPrs = new javax.swing.JTextField();
        ckBerlaku = new javax.swing.JCheckBox();
        txtBnsBksRp = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        btnEdit = new javax.swing.JButton();
        btnCariPegawai = new javax.swing.JButton();
        btnInfo = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtBnsJualPrs = new javax.swing.JTextField();
        txtBnsJualRp = new javax.swing.JTextField();
        rbPenjualan = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        rbBungkus = new javax.swing.JRadioButton();
        btnInfo1 = new javax.swing.JButton();
        pnShow = new javax.swing.JPanel();
        pnBonusPeg = new javax.swing.JPanel();
        spBonusPeg = new javax.swing.JScrollPane();
        tbBonusPeg = new javax.swing.JTable();
        pnSearchBonusPeg = new javax.swing.JPanel();
        btnBonusSearch = new javax.swing.JButton();
        btnBonusShowAll = new javax.swing.JButton();
        txtSrcBonusPeg = new javax.swing.JTextField();
        cbSrcBonusPeg = new javax.swing.JComboBox();
        infoBonusPeg = new javax.swing.JLabel();
        pnPegawai = new javax.swing.JPanel();
        pnCrPegawai = new javax.swing.JPanel();
        spPegawai = new javax.swing.JScrollPane();
        tbPegawai = new javax.swing.JTable();
        pnAtas1 = new javax.swing.JPanel();
        btnShowAllPegawai = new javax.swing.JButton();
        txtSrcPegawai = new javax.swing.JTextField();
        cbSrcPegawai = new javax.swing.JComboBox();
        btnSearchPegawai = new javax.swing.JButton();
        lblClosePegawai = new javax.swing.JLabel();
        infoPegawai = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Pengaturan Bonus");
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/bonus.png"))); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        pnTengah.setBackground(new java.awt.Color(255, 255, 255));
        pnTengah.setLayout(new java.awt.BorderLayout());

        pnAtas.setBackground(new java.awt.Color(255, 255, 255));
        pnAtas.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255), 2));
        pnAtas.setPreferredSize(new java.awt.Dimension(410, 250));
        pnAtas.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });
        pnAtas.add(btnDelete, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 80, 70, 20));

        txtUserName.setEditable(false);
        txtUserName.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pnAtas.add(txtUserName, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 40, 110, -1));

        jLabel2.setText("Username");
        pnAtas.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, -1, -1));

        txtKdBonus.setEditable(false);
        txtKdBonus.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtKdBonus.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtKdBonusKeyReleased(evt);
            }
        });
        pnAtas.add(txtKdBonus, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 10, 70, -1));

        jLabel3.setText("Kode Bonus");
        pnAtas.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jLabel4.setText("Keterangan");
        pnAtas.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 180, -1, -1));

        txtKet.setColumns(20);
        txtKet.setRows(5);
        jScrollPane1.setViewportView(txtKet);

        pnAtas.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 180, 240, 50));

        btnNew.setText("New");
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });
        pnAtas.add(btnNew, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 20, 70, -1));

        txtNmPegawai.setEditable(false);
        pnAtas.add(txtNmPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 60, 240, -1));

        jLabel5.setForeground(new java.awt.Color(0, 0, 204));
        jLabel5.setText("*pilih salah satu");
        pnAtas.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 90, -1, -1));

        jLabel6.setText("Bonus/bungkus");
        pnAtas.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, -1, -1));

        txtBnsBksPrs.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBnsBksPrs.setText("0");
        txtBnsBksPrs.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtBnsBksPrsFocusLost(evt);
            }
        });
        txtBnsBksPrs.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtBnsBksPrsKeyTyped(evt);
            }
        });
        pnAtas.add(txtBnsBksPrs, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 110, 40, -1));

        ckBerlaku.setBackground(new java.awt.Color(255, 255, 255));
        ckBerlaku.setText("Berlaku");
        pnAtas.add(ckBerlaku, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 10, -1, -1));

        txtBnsBksRp.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBnsBksRp.setText("0");
        txtBnsBksRp.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtBnsBksRpFocusLost(evt);
            }
        });
        txtBnsBksRp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtBnsBksRpKeyTyped(evt);
            }
        });
        pnAtas.add(txtBnsBksRp, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 110, 90, -1));

        jLabel7.setText("%");
        pnAtas.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 110, -1, -1));

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        pnAtas.add(btnEdit, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 50, 70, 20));

        btnCariPegawai.setText("cari");
        btnCariPegawai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariPegawaiActionPerformed(evt);
            }
        });
        pnAtas.add(btnCariPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 40, -1, 20));

        btnInfo.setText("?");
        btnInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInfoActionPerformed(evt);
            }
        });
        pnAtas.add(btnInfo, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 140, 30, -1));

        jLabel8.setText("Nama Pegawai");
        pnAtas.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));

        jLabel9.setText("Bonus/penjualan");
        pnAtas.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, -1, -1));

        jLabel10.setText("%");
        pnAtas.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(190, 140, -1, -1));

        txtBnsJualPrs.setEditable(false);
        txtBnsJualPrs.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBnsJualPrs.setText("0");
        txtBnsJualPrs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtBnsJualPrsActionPerformed(evt);
            }
        });
        pnAtas.add(txtBnsJualPrs, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 140, 40, -1));

        txtBnsJualRp.setEditable(false);
        txtBnsJualRp.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtBnsJualRp.setText("0");
        pnAtas.add(txtBnsJualRp, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 140, 90, -1));

        rbPenjualan.setBackground(new java.awt.Color(255, 255, 255));
        rbPenjualan.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                rbPenjualanStateChanged(evt);
            }
        });
        rbPenjualan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbPenjualanActionPerformed(evt);
            }
        });
        pnAtas.add(rbPenjualan, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 140, -1, -1));

        jLabel11.setText("Rp");
        pnAtas.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 110, -1, -1));

        jLabel12.setText("Rp");
        pnAtas.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 140, -1, -1));

        rbBungkus.setBackground(new java.awt.Color(255, 255, 255));
        rbBungkus.setSelected(true);
        rbBungkus.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                rbBungkusStateChanged(evt);
            }
        });
        rbBungkus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbBungkusActionPerformed(evt);
            }
        });
        pnAtas.add(rbBungkus, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 110, -1, -1));

        btnInfo1.setText("?");
        btnInfo1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInfo1ActionPerformed(evt);
            }
        });
        pnAtas.add(btnInfo1, new org.netbeans.lib.awtextra.AbsoluteConstraints(330, 110, 30, -1));

        pnTengah.add(pnAtas, java.awt.BorderLayout.PAGE_START);

        pnShow.setLayout(new java.awt.CardLayout());

        pnBonusPeg.setLayout(new java.awt.BorderLayout());

        spBonusPeg.setAutoscrolls(true);

        tbBonusPeg.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbBonusPeg.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tbBonusPeg.setGridColor(new java.awt.Color(0, 0, 255));
        tbBonusPeg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbBonusPegMousePressed(evt);
            }
        });
        tbBonusPeg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbBonusPegKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tbBonusPegKeyReleased(evt);
            }
        });
        spBonusPeg.setViewportView(tbBonusPeg);

        pnBonusPeg.add(spBonusPeg, java.awt.BorderLayout.CENTER);

        pnSearchBonusPeg.setBackground(new java.awt.Color(255, 255, 255));
        pnSearchBonusPeg.setPreferredSize(new java.awt.Dimension(0, 70));
        pnSearchBonusPeg.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnBonusSearch.setText("Search");
        btnBonusSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBonusSearchActionPerformed(evt);
            }
        });
        pnSearchBonusPeg.add(btnBonusSearch, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 40, 80, -1));

        btnBonusShowAll.setText("Show All");
        btnBonusShowAll.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBonusShowAllActionPerformed(evt);
            }
        });
        pnSearchBonusPeg.add(btnBonusShowAll, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 10, 80, -1));
        pnSearchBonusPeg.add(txtSrcBonusPeg, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 40, 210, 20));

        cbSrcBonusPeg.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Kode Bonus", "Nama" }));
        pnSearchBonusPeg.add(cbSrcBonusPeg, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 100, 20));

        infoBonusPeg.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        infoBonusPeg.setForeground(new java.awt.Color(0, 0, 204));
        infoBonusPeg.setText("Search Data Bonus Pegawai");
        pnSearchBonusPeg.add(infoBonusPeg, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, 20));

        pnBonusPeg.add(pnSearchBonusPeg, java.awt.BorderLayout.PAGE_START);

        pnShow.add(pnBonusPeg, "bonuspegawai");

        pnPegawai.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 204)));
        pnPegawai.setLayout(new java.awt.BorderLayout());

        pnCrPegawai.setBackground(new java.awt.Color(255, 255, 255));
        pnCrPegawai.setLayout(new java.awt.BorderLayout());

        tbPegawai.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbPegawai.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tbPegawai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbPegawaiMousePressed(evt);
            }
        });
        tbPegawai.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tbPegawaiKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tbPegawaiKeyReleased(evt);
            }
        });
        spPegawai.setViewportView(tbPegawai);

        pnCrPegawai.add(spPegawai, java.awt.BorderLayout.CENTER);

        pnAtas1.setBackground(new java.awt.Color(255, 255, 255));
        pnAtas1.setPreferredSize(new java.awt.Dimension(410, 70));
        pnAtas1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        btnShowAllPegawai.setText("Show All");
        btnShowAllPegawai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnShowAllPegawaiActionPerformed(evt);
            }
        });
        pnAtas1.add(btnShowAllPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 40, 80, -1));
        pnAtas1.add(txtSrcPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 40, 270, -1));

        cbSrcPegawai.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Username", "Nama" }));
        pnAtas1.add(cbSrcPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 100, -1));

        btnSearchPegawai.setText("Search");
        btnSearchPegawai.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchPegawaiActionPerformed(evt);
            }
        });
        pnAtas1.add(btnSearchPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 10, 80, -1));

        lblClosePegawai.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Delete.png"))); // NOI18N
        lblClosePegawai.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblClosePegawaiMouseClicked(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lblClosePegawaiMouseReleased(evt);
            }
        });
        pnAtas1.add(lblClosePegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 20, 40, 40));

        infoPegawai.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        infoPegawai.setForeground(new java.awt.Color(0, 0, 204));
        infoPegawai.setText("Data Pegawai");
        pnAtas1.add(infoPegawai, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, -1, -1));

        pnCrPegawai.add(pnAtas1, java.awt.BorderLayout.PAGE_START);

        pnPegawai.add(pnCrPegawai, java.awt.BorderLayout.CENTER);

        pnShow.add(pnPegawai, "pegawai");

        pnTengah.add(pnShow, java.awt.BorderLayout.CENTER);

        getContentPane().add(pnTengah, java.awt.BorderLayout.CENTER);

        setBounds(0, 0, 453, 462);
    }// </editor-fold>//GEN-END:initComponents

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        // TODO add your handling code here:
        int clossing;
        clossing = JOptionPane.showConfirmDialog(this,
                "Tutup Pengaturan Bonus?",
                "Konfirmasi",
                JOptionPane.YES_NO_OPTION);
        if (clossing == 0){
            this.dispose();
            FormMain.isfBon = false;
        }
    }//GEN-LAST:event_formInternalFrameClosing

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        // TODO add your handling code here:
        if(btnDelete.getText().equals("Cancel")){
            kosongkan();
            tampilDataBonusPeg();
        }else if(btnDelete.getText().equals("Delete")){
            deleteData();
        }

        //*
        //*/
}//GEN-LAST:event_btnDeleteActionPerformed

    private void txtKdBonusKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtKdBonusKeyReleased
        // TODO add your handling code here:
}//GEN-LAST:event_txtKdBonusKeyReleased

    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        // TODO add your handling code here:
        kosongkanNew();
}//GEN-LAST:event_btnNewActionPerformed

    private void txtBnsBksPrsFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBnsBksPrsFocusLost
        // TODO add your handling code here:
        if (!txtBnsBksPrs.getText().equals("0")){
            txtBnsBksRp.setText("0");
        }
}//GEN-LAST:event_txtBnsBksPrsFocusLost

    private void txtBnsBksPrsKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBnsBksPrsKeyTyped
        // TODO add your handling code here:
        if (!txtBnsBksPrs.getText().equals("0")){
            txtBnsBksRp.setText("0");
        }
}//GEN-LAST:event_txtBnsBksPrsKeyTyped

    private void txtBnsBksRpFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBnsBksRpFocusLost
        // TODO add your handling code here:
        if (!txtBnsBksRp.getText().equals("0")){
            txtBnsBksPrs.setText("0");
        }
}//GEN-LAST:event_txtBnsBksRpFocusLost

    private void txtBnsBksRpKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtBnsBksRpKeyTyped
        // TODO add your handling code here:
        if (!txtBnsBksRp.getText().equals("0")){
            txtBnsBksPrs.setText("0");
        }
}//GEN-LAST:event_txtBnsBksRpKeyTyped

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        // TODO add your handling code here:
        if(btnEdit.getText().equals("Save")){
            if(txtUserName.getText().equals("")){
                JOptionPane.showMessageDialog(this, "Username harus diisi!",
                        "Informasi",JOptionPane.INFORMATION_MESSAGE);
            }else{
                if(!txtBnsBksPrs.getText().equals("") || !txtBnsBksRp.getText().equals("") ) {
                    if(isDuplicatePKey()==true){
                        kosongkanNew();
                        txtKdBonus.requestFocus();
                    }else{
                        insertData();
                    }
                }else{
                    JOptionPane.showMessageDialog(this, "persen bonus atau rp bonus" +
                            " harus diisi!",
                            "Informasi",JOptionPane.INFORMATION_MESSAGE);
                }
            }
        }else if (btnEdit.getText().equals("Edit")){
            editData();
        }
}//GEN-LAST:event_btnEditActionPerformed

    private void btnCariPegawaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariPegawaiActionPerformed
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "pegawai");
        tampilSearchPegawai();
        kosongkanNew();
}//GEN-LAST:event_btnCariPegawaiActionPerformed

    private void btnInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInfoActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(this, "oi " +
                "oi oi oi","informasi",JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_btnInfoActionPerformed

    private void tbBonusPegMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbBonusPegMousePressed
        getDataFromBonusPeg();
}//GEN-LAST:event_tbBonusPegMousePressed

    private void tbBonusPegKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbBonusPegKeyPressed
        // TODO add your handling code here:
        getDataFromBonusPeg();
}//GEN-LAST:event_tbBonusPegKeyPressed

    private void tbBonusPegKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbBonusPegKeyReleased
        // TODO add your handling code here:
        getDataFromBonusPeg();
}//GEN-LAST:event_tbBonusPegKeyReleased

    private void btnBonusSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBonusSearchActionPerformed
        // TODO add your handling code here:
        tampilSearchBonusPeg();
        btnEdit.setEnabled(false);
        btnDelete.setEnabled(false);
}//GEN-LAST:event_btnBonusSearchActionPerformed

    private void btnBonusShowAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBonusShowAllActionPerformed
        // TODO add your handling code here:
        tampilDataBonusPeg();
}//GEN-LAST:event_btnBonusShowAllActionPerformed

    private void tbPegawaiMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbPegawaiMousePressed
        getDataFromPegawai();
}//GEN-LAST:event_tbPegawaiMousePressed

    private void tbPegawaiKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbPegawaiKeyPressed
        // TODO add your handling code here:
        getDataFromPegawai();
}//GEN-LAST:event_tbPegawaiKeyPressed

    private void tbPegawaiKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbPegawaiKeyReleased
        // TODO add your handling code here:
        getDataFromPegawai();
}//GEN-LAST:event_tbPegawaiKeyReleased

    private void btnShowAllPegawaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowAllPegawaiActionPerformed
        // TODO add your handling code here:
        tampilAllPegawai();
}//GEN-LAST:event_btnShowAllPegawaiActionPerformed

    private void btnSearchPegawaiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchPegawaiActionPerformed
        // TODO add your handling code here:
        tampilSearchPegawai();
}//GEN-LAST:event_btnSearchPegawaiActionPerformed

    private void lblClosePegawaiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClosePegawaiMouseClicked
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "bonuspegawai");
}//GEN-LAST:event_lblClosePegawaiMouseClicked

    private void lblClosePegawaiMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblClosePegawaiMouseReleased
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(pnShow.getLayout());
        cl.show(pnShow, "bonuspegawai");
}//GEN-LAST:event_lblClosePegawaiMouseReleased

    private void txtBnsJualPrsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBnsJualPrsActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtBnsJualPrsActionPerformed

    private void btnInfo1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInfo1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnInfo1ActionPerformed

    private void rbBungkusStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_rbBungkusStateChanged
        // TODO add your handling code here:
        
    }//GEN-LAST:event_rbBungkusStateChanged

    private void rbPenjualanStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_rbPenjualanStateChanged
        // TODO add your handling code here:
        
    }//GEN-LAST:event_rbPenjualanStateChanged

    private void rbBungkusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbBungkusActionPerformed
        // TODO add your handling code here:
        txtBnsJualPrs.setText("0");
        txtBnsJualRp.setText("0");
        txtBnsJualPrs.setEditable(false);
        txtBnsJualRp.setEditable(false);
        txtBnsBksPrs.setEditable(true);
        txtBnsBksRp.setEditable(true); 
    }//GEN-LAST:event_rbBungkusActionPerformed

    private void rbPenjualanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbPenjualanActionPerformed
        // TODO add your handling code here:
        txtBnsBksPrs.setText("0");
        txtBnsBksRp.setText("0");
        txtBnsBksPrs.setEditable(false);
        txtBnsBksRp.setEditable(false);
        txtBnsJualPrs.setEditable(true);
        txtBnsJualRp.setEditable(true);
    }//GEN-LAST:event_rbPenjualanActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBonusSearch;
    private javax.swing.JButton btnBonusShowAll;
    private javax.swing.JButton btnCariPegawai;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnInfo;
    private javax.swing.JButton btnInfo1;
    private javax.swing.JButton btnNew;
    private javax.swing.JButton btnSearchPegawai;
    private javax.swing.JButton btnShowAllPegawai;
    private javax.swing.JComboBox cbSrcBonusPeg;
    private javax.swing.JComboBox cbSrcPegawai;
    private javax.swing.JCheckBox ckBerlaku;
    private javax.swing.JLabel infoBonusPeg;
    private javax.swing.JLabel infoPegawai;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblClosePegawai;
    private javax.swing.JPanel pnAtas;
    private javax.swing.JPanel pnAtas1;
    private javax.swing.JPanel pnBonusPeg;
    private javax.swing.JPanel pnCrPegawai;
    private javax.swing.JPanel pnPegawai;
    private javax.swing.JPanel pnSearchBonusPeg;
    private javax.swing.JPanel pnShow;
    private javax.swing.JPanel pnTengah;
    private javax.swing.JRadioButton rbBungkus;
    private javax.swing.JRadioButton rbPenjualan;
    private javax.swing.JScrollPane spBonusPeg;
    private javax.swing.JScrollPane spPegawai;
    private javax.swing.JTable tbBonusPeg;
    private javax.swing.JTable tbPegawai;
    private javax.swing.JTextField txtBnsBksPrs;
    private javax.swing.JTextField txtBnsBksRp;
    private javax.swing.JTextField txtBnsJualPrs;
    private javax.swing.JTextField txtBnsJualRp;
    private javax.swing.JTextField txtKdBonus;
    private javax.swing.JTextArea txtKet;
    private javax.swing.JTextField txtNmPegawai;
    private javax.swing.JTextField txtSrcBonusPeg;
    private javax.swing.JTextField txtSrcPegawai;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables

    private void kosongkan(){
        txtUserName.setText("");
        txtNmPegawai.setText("");
        txtBnsBksPrs.setText("");
        txtBnsBksRp.setText("");
        txtKet.setText("");
        txtSrcBonusPeg.setText("");
        btnEdit.setEnabled(false);
        btnDelete.setEnabled(false);
        btnEdit.setText("Edit");
        btnDelete.setText("Delete");
        ckBerlaku.setSelected(false);
    }
    private void kosongkanNew(){
        setKdBonusPeg();
        txtUserName.setText("");
        txtNmPegawai.setText("");
        txtBnsBksPrs.setText("");
        txtBnsBksRp.setText("");
        txtKet.setText("");
        txtSrcBonusPeg.setText("");
        btnEdit.setText("Save");
        btnDelete.setText("Cancel");
        btnEdit.setEnabled(true);
        btnDelete.setEnabled(true);
        ckBerlaku.setSelected(true);
    }
    private void tampilDataBonusPeg(){
        Object[] Baris={"Kode", "Nama", "Bonus %", "Bonus Rp"};
        DftTabModeBonusPeg=new DefaultTableModel(null,Baris);
        tbBonusPeg.setModel(DftTabModeBonusPeg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("SELECT b.*, p.nmPeg " +
                    "FROM tbonus b, tpeg p WHERE b.kdPeg = p.user_id");
            while (rslt.next()) {
                String sKdBonus = rslt.getString("kdBonus");
                String sNmPeg = rslt.getString("nmPeg");
                String sPrs = rslt.getString("bonus_prs");
                String sRp = rslt.getString("bonus_rp");

                String[] dataField = {sKdBonus, sNmPeg, sPrs, sRp};
                DftTabModeBonusPeg.addRow(dataField);
                int widths[] = {60, 270, 50, 100};
                for(int i=0;i<tbBonusPeg.getColumnCount();i++){
                    TableColumn column = tbBonusPeg.getColumnModel().getColumn(i);
                    column.setPreferredWidth(widths[i]);
                }
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
    }

    private void tampilSearchBonusPeg(){
        String srcby = "";
        if(cbSrcBonusPeg.getSelectedItem().toString().equals("Kode Bonus")){
            srcby = "kdBonus";
        }else if(cbSrcBonusPeg.getSelectedItem().toString().equals("Nama")){
            srcby = "nmPeg";
        }

        Object[] Baris={"Kode","Nama", "Bonus %", "Bonus Rp"};
        DftTabModeBonusPeg=new DefaultTableModel(null,Baris);
        tbBonusPeg.setModel(DftTabModeBonusPeg);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT b.*, p.nmPeg FROM tbonus b, tpeg p " +
                    "WHERE b.kdPeg = p.user_id " +
                    "AND UPPER(" + srcby +
                    ") like UPPER('%" +
                    txtSrcBonusPeg.getText() + "%')");
            while (rslt.next()) {
                String sKdBonus = rslt.getString("kdBonus");
                String sNmPeg = rslt.getString("nmPeg");
                String sBonusPrs = rslt.getString("bonus_prs");
                String sBonusRp = rslt.getString("bonus_rp");
                //String sNamaKota = rslt.getString("ket");

                String[] dataField = {sKdBonus, sNmPeg, sBonusPrs, sBonusRp};
                DftTabModeBonusPeg.addRow(dataField);
                int widths[] = {60, 270, 50, 100};
                for(int i=0;i<tbBonusPeg.getColumnCount();i++){
                    TableColumn column = tbBonusPeg.getColumnModel().getColumn(i);
                    column.setPreferredWidth(widths[i]);
                }
            }

        }
        catch(SQLException e) {
            System.out.println("gagal! : " + e.toString());
        }
    }

    private void tampilSearchPegawai(){
        String srcby = "";
        if(cbSrcPegawai.getSelectedItem().toString().equals("Username")){
            srcby = "user_id";
        }else{
            srcby = "nmPeg";
        }

        Object[] Baris={"Kode","Nama"};
        DftTabModePegawai=new DefaultTableModel(null,Baris);
        tbPegawai.setModel(DftTabModePegawai);
        int widths[] = {120, 300};
        for(int i=0;i<tbPegawai.getColumnCount();i++){
            TableColumn column = tbPegawai.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tpeg " +
                    "WHERE UPPER(" + srcby +
                    ") like UPPER('%" +
                    txtSrcPegawai.getText() + "%')");
            while (rslt.next()) {
                String sKdPeg = rslt.getString("user_id");
                String sNmPeg = rslt.getString("nmPeg");

                String[] dataField = {sKdPeg, sNmPeg};
                DftTabModePegawai.addRow(dataField);
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
    }

    private void deleteData(){
            try {
                int deleting;
                deleting = JOptionPane.showConfirmDialog(this,
                        "Apakah Anda yakin akan menghapus "

                        //+ cbKodeKota.getSelectedItem().toString() +" "
                        +txtKdBonus.getText() +"?",
                        "Konfirmasi",
                        JOptionPane.YES_NO_OPTION);
                if (deleting == 0){

                    PreparedStatement pStatement = null;
                    String sql = "DELETE FROM tbonus " +
                            "WHERE kdBonus=? ";
                    pStatement = conn.prepareStatement(sql);

                    pStatement.setString(1, txtKdBonus.getText());

                    int intTambah = pStatement.executeUpdate();
                    if (intTambah >0){
                        JOptionPane.showMessageDialog(this,
                                "Delete sukses", "Informasi",
                                JOptionPane.INFORMATION_MESSAGE);

                    }else {
                        JOptionPane.showMessageDialog(this,
                                "Delete gagal", "Informasi",
                                JOptionPane.INFORMATION_MESSAGE);
                    }

                    pStatement.close();

                    kosongkan();
                    tampilDataBonusPeg();
                }
            } catch(SQLException e){
                System.out.println("koneksi gagal " + e.toString());
            }
    }
    private boolean isDuplicatePKey(){
        String pKey = txtKdBonus.getText();
        boolean result = true;
        int row = 0;

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("Select * from tbonus " +
                    "WHERE kdBonus=" +
                    "'" +pKey+ "'");
            while (rslt.next()) {
                row = rslt.getRow();
            }
                if(row > 0){
                    JOptionPane.showMessageDialog(this, "Kode "+pKey+" sudah ada"
                            ,"Peringatan",JOptionPane.WARNING_MESSAGE);
                    result = true;
                }else{
                    result = false;
                }
            System.out.println("row : " + row);
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        return result;
    }
    private void insertData(){
        // panggil method koneksi
        //java.sql.Connection conn = new DBConnection().connect();

        boolean selected = ckBerlaku.isSelected();
        String berlaku = "";
        if (selected){
            berlaku ="1";
        }else{
            berlaku = "0";
        }

        java.sql.PreparedStatement pStatement = null;
        String sql = "INSERT INTO tbonus " +
                "(kdBonus, kdPeg, ket, bonus_prs, bonus_rp," +
                "berlaku,tgl_insert, tgl_update) " +
                "VALUES (?,?,?,?,?,?,now(), now())";
        try {
            pStatement = conn.prepareStatement(sql);
            pStatement.setString(1, txtKdBonus.getText());
            pStatement.setString(2, txtUserName.getText());
            pStatement.setString(3, txtKet.getText());
            pStatement.setString(4, txtBnsBksPrs.getText());
            pStatement.setString(5, txtBnsBksRp.getText());
            pStatement.setString(6, berlaku);
            //String kdKota = (String)cbKodeKota.getSelectedItem();
            //pStatement.setString(2, kdKota);

            int intTambah = pStatement.executeUpdate();
            if (intTambah>0){
                JOptionPane.showMessageDialog(this,
                        "Penambahan sukses", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(this,
                        "Penambahan gagal", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);
            }
            pStatement.close();
            //conn.close();

            kosongkan();
            tampilDataBonusPeg();
            setKdBonusPeg();

        }
        catch(SQLException e){
            System.out.println("koneksi gagal " + e.toString());
        }

    }

     private void editData(){
        boolean selected = ckBerlaku.isSelected();
        String berlaku = "";
        if (selected){
            berlaku ="1";
        }else{
            berlaku = "0";
        }
        try {
            PreparedStatement pStatement = null;
            String sql = "UPDATE tbonus " +
                    "SET kdPeg=?, ket=?, " +
                    "bonus_prs=?, bonus_rp=?, " +
                    "berlaku=? " +
                    "WHERE kdBonus=? ";
            pStatement = conn.prepareStatement(sql);

            //pStatement.setString(1, cbKodeKota.getSelectedItem().toString());

            pStatement.setString(1, txtUserName.getText());
            pStatement.setString(2, txtKet.getText());
            pStatement.setFloat(3, Float.parseFloat(txtBnsBksPrs.getText()));
                    //setString(3, txtDPrs.getText());
            pStatement.setDouble(4, Double.parseDouble(txtBnsBksRp.getText()));
            pStatement.setString(5, berlaku);
            pStatement.setString(6, txtKdBonus.getText());

            int intTambah = pStatement.executeUpdate();
            if (intTambah >0){
                JOptionPane.showMessageDialog(this,
                        "Edit sukses", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);

            }else {
                JOptionPane.showMessageDialog(this,
                        "Edit gagal", "Informasi",
                        JOptionPane.INFORMATION_MESSAGE);
            }


            pStatement.close();
            kosongkan();
            tampilDataBonusPeg();

        } catch(SQLException e){
            System.out.println("koneksi gagal " + e.toString());
        }
    }
    private void getDataFromBonusPeg(){
                // TODO add your handling code here:
        Object oKdBonus, oNmPeg, oBonusPrs, oBonusRp;//, oTest;

        oKdBonus = tbBonusPeg.getValueAt(tbBonusPeg.getSelectedRow(), 0);
        oNmPeg = tbBonusPeg.getValueAt(tbBonusPeg.getSelectedRow(), 1);
        oBonusPrs = tbBonusPeg.getValueAt(tbBonusPeg.getSelectedRow(), 2);
        oBonusRp = tbBonusPeg.getValueAt(tbBonusPeg.getSelectedRow(), 3);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery("SELECT b.*, p.user_id, p.nmPeg " +
                    "FROM tbonus b, tpeg p WHERE b.kdPeg = p.user_id " +
                    "AND kdBonus=" +
                    "'" +oKdBonus+ "'");
            while (rslt.next()) {
                txtUserName.setText(rslt.getString("user_id"));
                txtKet.setText(rslt.getString("ket"));

                if(rslt.getString("berlaku").toString().equals("1")){
                    ckBerlaku.setSelected(true);
                }else{
                    ckBerlaku.setSelected(false);
                }
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }

        /*
        if(oTest == null){
            oTest = " ";
        }
         *
         */

        txtKdBonus.setText(oKdBonus.toString());
        txtNmPegawai.setText(oNmPeg.toString());
        txtBnsBksPrs.setText(oBonusPrs.toString());
        txtBnsBksRp.setText(oBonusRp.toString());

        btnEdit.setEnabled(true);
        btnDelete.setEnabled(true);
        btnEdit.setText("Edit");
        btnDelete.setText("Delete");

    }

    private void setKdBonusPeg(){
        String kdBonus = "";
        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tbonus");
            //int iNo = 0;
            while (rslt.next()) {
                int row = rslt.getRow();
                kdBonus = rslt.getString("kdBonus");
            }
        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }
        if(kdBonus.equals("")){
            kdBonus = "B000";
        }

        System.out.println(kdBonus);
        kdBonus = kdBonus.substring(2);
        System.out.println(kdBonus);
        Integer noUrut;
        noUrut = Integer.parseInt(kdBonus);
        noUrut++;
        java.text.DecimalFormat nft = new java.text.DecimalFormat("#000.###");
        nft.setDecimalSeparatorAlwaysShown(false);
        System.out.println("B"+nft.format(noUrut));
        txtKdBonus.setText("B"+nft.format(noUrut));
    }

    private void getDataFromPegawai(){
                // TODO add your handling code here:
        Object oKdPeg, oNmPeg;//, oKet;//, oTest;

        oKdPeg = tbPegawai.getValueAt(tbPegawai.getSelectedRow(), 0);
        oNmPeg = tbPegawai.getValueAt(tbPegawai.getSelectedRow(), 1);

        //cbKodeKota.setSelectedItem(oKdKota);
        txtUserName.setText(oKdPeg.toString());
        txtNmPegawai.setText(oNmPeg.toString());
        //setHarga();
    }

    private void tampilAllPegawai(){
        
        txtSrcPegawai.setText("");

        Object[] Baris={"Kode","Nama"};
        DftTabModePegawai=new DefaultTableModel(null,Baris);
        tbPegawai.setModel(DftTabModePegawai);

        try {
            java.sql.Statement stmt = conn.createStatement();
            java.sql.ResultSet rslt = stmt.executeQuery(
                    "SELECT * FROM tpeg");
            while (rslt.next()) {
                String sKdPeg = rslt.getString("user_id");
                String sNamaPeg = rslt.getString("nmPeg");

                String[] dataField = {sKdPeg, sNamaPeg};
                DftTabModePegawai.addRow(dataField);
                int widths[] = {120, 300};
                for(int i=0;i<tbPegawai.getColumnCount();i++){
                    TableColumn column = tbPegawai.getColumnModel().getColumn(i);
                    column.setPreferredWidth(widths[i]);
                }
            }

        }
        catch(SQLException e) {
            System.out.println("gagal : " + e.toString());
        }

    }    
}
